package org.example.common.config;

import lombok.extern.slf4j.Slf4j;
import org.example.common.ex.GateWayException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@ControllerAdvice
@ResponseBody
@Slf4j
/**
 * 全局异常处理
 */
public class MyGlobalExceptionHandler {
    /**
     * runtime
     * @param exception
     * @return
     */
    @ExceptionHandler(GateWayException.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public CommonResult runtimeException(RuntimeException exception) {
        String message = exception.getMessage();
        CommonResult result = new CommonResult();
        result.setCode(ResultCode.FORBIDDEN.getCode());
        result.setMessage(message);
        return result;
    }

}
